package com.sdlg.controller;


import com.sdlg.service.OrderService;
import com.sdlg.util.QueryPageBean;
import com.sdlg.util.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sdlg
 * @since 2024-12-26
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;
    @RequestMapping("/showOrderDetailInfo")
    public Result showOrderDetailInfo(@RequestBody QueryPageBean queryPageBean, HttpServletRequest request){
        Integer userId = (Integer) request.getSession().getAttribute("user_id");
        Integer role = (Integer) request.getSession().getAttribute("role_id");
        System.out.println("----------------------------------------------------------");
        System.out.println(userId);
        System.out.println(role);
        Result result=null;
        if(role==1){
            result=orderService.showOrderDetailInfo(queryPageBean);
        }else if(role==3){
            result=orderService.showMemberOrderDetailInfo(queryPageBean,userId);
        }

        return result;
    }

    @RequestMapping("/showOrderWarnInfo")
    public Result showOrderWarnInfo(HttpServletRequest request){
        Integer userId = (Integer) request.getSession().getAttribute("user_id");
        Integer role = (Integer) request.getSession().getAttribute("role_id");
        System.out.println("----------------------------------------------------------");
        System.out.println(userId);
        System.out.println(role);
        Result result=null;
        if(role==1){
            result=null;
        }else if(role==3){
            result=orderService.showOrderWarnInfo(userId);
        }
        return result;
    }



    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        Result result=orderService.deleteById(id);
        return result;
    }

    @RequestMapping("/returnById")
    public Result returnById(Integer id){
        Result result=orderService.returnById(id);
        return result;
    }
    @RequestMapping("/remarkById")
    public Result remarkById(Integer id){
        Result result=orderService.remarkById(id);
        return result;
    }
    @RequestMapping("/moneyById")
    public Result moneyById(Integer id){
        Result result=orderService.moneyById(id);
        return result;
    }

    @RequestMapping("/buyById")
    public Result buyById(Integer id){
        Result result=orderService.buyById(id);
        return result;
    }
    @RequestMapping("/updateOrder")
    public Result updateOrder(Integer id){
        Result result=orderService.updateOrder(id);
        return result;
    }
}
